<template>
  <template v-for="(item, index) in props.menuData" :key="item.path">
    <el-menu-item
      @click="handleClick(item, item.path)"
      v-if="!item.children || item.children.length === 0"
      :index="item.path"
      :key="item.path"
    >
      <el-icon size="20">
        <component :is="item.meta.icon"></component>
      </el-icon>
      <span>{{ item.meta.name }}</span>
    </el-menu-item>
    <el-sub-menu v-else :index="item.path">
      <template #title>
        <el-icon size="20">
          <component :is="item.meta.icon"></component>
        </el-icon>
        <span>{{ item.meta.name }}</span>
      </template>
      <tree-menu :index="item.path" :menuData="item.children" />
    </el-sub-menu>
  </template>
</template>

<script setup>
import { useRouter } from "vue-router";
import { useAllMenuDataStore } from "@/store/menu.js";
import { computed } from "vue";
import { watch } from "vue";
const menuStore = useAllMenuDataStore();
const router = useRouter();
const props = defineProps(["menuData"]);
console.log("props.menuData", props.menuData);

const handleClick = (item) => {
  console.log("item", item);
  //  router.push({name:item.name});
  router.push(item.path); // 跳转到对应的路由路径，这里的path是路由的path属性，不是name属性，所以不需要写name:item.name
  // menuStore.selectMenu(item);
};


</script>
<style scoped lang="less"></style>
